﻿using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Net;
using System.Net.Mail;
using System.Web;
using System.Web.UI.WebControls;

/// <summary>
/// Summary description for EmailManager
/// </summary>
public class EmailManager
{
    MailDefinition md = new MailDefinition();
    private String fromAddress = "debioscoop@vdlmark.com";
    private String fromPassword = "debioscoop123";
    private List<Attachment> attachments = new List<Attachment>();

	public EmailManager()
	{
        md.From = fromAddress;
        md.IsBodyHtml = true;
	}

    public void setPDFAttachments(List<String> tempPDF)
    {
        foreach (String pdf in tempPDF)
        {
            Attachment attach = new Attachment(pdf);
            attachments.Add(attach);
        }
    }

    public void sendEmail(String email, String subject, ListDictionary replacements, String body)
    {
        md.Subject = subject;
        MailMessage msg = md.CreateMailMessage(email, replacements, body, new System.Web.UI.Control());
        foreach (Attachment attach in attachments)
        {
            msg.Attachments.Add(attach);
        }

        var smtp = new System.Net.Mail.SmtpClient();
        {
            smtp.Host = "mail.antagonist.nl";
            smtp.Port = 587;
            smtp.EnableSsl = true;
            smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;

            smtp.Credentials = new NetworkCredential(fromAddress, fromPassword);
            smtp.Timeout = 1000;
        }
        smtp.Send(msg);
    }
}